#include "myLib.h"
#include "silib.h"
#include "startScreen.h"
#include <stdlib.h>
/*
Kyle Kelly
HW9
CS2110-B2
*/
extern Ship ship;

int main(){
	REG_DISPCNT = MODE3 | BG2_ENABLE;
	int aWasPressed = 0;
    int selectWasPressed = 0;
	srand(waitForStart()); //initially holds game "hostage"
	newGame();
	while(1)
	{		
		updateInvaders();
		waitForVblank();
		if(KEY_PRESSED(BUTTON_LEFT))
		{
			moveLeft();
		}
		else if (KEY_PRESSED(BUTTON_RIGHT))
		{
			moveRight();
		}
		if(KEY_PRESSED(BUTTON_SELECT) && (selectWasPressed == 0))
		{
		    clearScreen();
		    waitForStart();
		    newGame();
		}
		if (KEY_PRESSED(BUTTON_A) && (ship.bullets != 0)&&(!aWasPressed))
		{
			playerFire();	
		}
		aWasPressed = KEY_PRESSED(BUTTON_A);
		selectWasPressed = KEY_PRESSED(BUTTON_SELECT);
		drawInvaders();
		invadersTryFire();
		updateBullets();
		checkCollisions();
		checkWinConditions();   //can hold game "hostage"
        checkLoseConditions();  //can hold game "hostage"
	}
}


